﻿using ABMyFconBD.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


namespace ABMyFconBD.Controllers
{

    public class HomeController : Controller
    {
        private AlumnoContenedor alumnoContenedor = new AlumnoContenedor();
        
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var listaAlumno = alumnoContenedor.alumnos;
            
            // laListaDeLinks.Count();
            return View(model: listaAlumno);
        }

        [HttpGet]
        public ActionResult Agregar()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Agregar(Alumno alumno)
        {
            alumnoContenedor.agregarAlumno(alumno);
            return RedirectToAction("Index");
        }

        [HttpGet]
        public ActionResult Editar(int id)
        {
            Alumno alumno = alumnoContenedor.alumnos.Find(id);
            return View(model: alumno);
        }

        [HttpPost]
        public ActionResult Editar(Alumno alumno)

        {

            Alumno alumnoBase = alumnoContenedor.alumnos.Find(alumno.id);
            alumnoBase.id = alumno.id;
            alumnoBase.nombre = alumno.nombre;
            alumnoBase.apellido = alumno.apellido;
            alumnoContenedor.SaveChanges();

            return RedirectToAction("Index");
        }
        //[HttpGet]
        //public ActionResult Borrar(int id)
        //{
        //    Alumno alumno = alumnoContenedor.alumnos.Find(id);
        //    return View(model: alumno);
        //}

        //[HttpPost]
        public ActionResult Borrar(Alumno alumno)
        {

            Alumno alumnoBase = alumnoContenedor.alumnos.Find(alumno.id);
            alumnoContenedor.alumnos.Remove(alumnoBase);
            alumnoContenedor.SaveChanges();

            return RedirectToAction("Index");
        }

    }

}

